def input_grade(n):
    total = {}
    with open('file_score.txt', mode='w', encoding='utf-8') as f:
        for i in range(1, n+1):
            name, c, e, m = input(f"请输入第一{i}个同学的姓名及语数外成绩:").split(' ')
            total_score = int(c) + int(e) + int(m)
            f.write(f'1     {name}    {c}    {e}   {m}\n')
            total[f'{name}'] = [c,e,m,total_score]
    return total


def grade_sort(total):
    ls = list(total.items())
    ls.sort(key=lambda x: x[1][3], reverse=True)
    total = list(total)
    print("名次   姓名   语文   英语   数学   总分   ")
    print('--------------------------------------')
    for k in range(1, n+1):
        print(k,end='')
        print(total[k-1])
        # print(total[0],end='     ')
        # print(total[1][0],end='     ')
        # print(total[1][1],end='     ')
        # print(total[1][2],end='     ')
        # print(total[1][3])


if __name__ == '__main__':
    n = 2
    # n = 5
    total = input_grade(n)
    grade_sort(total)
